home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 025a / isamto.zip / ISAMTOOT.L1 < prev   
Text File  |  1991-11-05  |  6KB  |  140 lines

  1. DEFINT A-Z      ' everything about integers is faster and memory saving.
  2.                 ' this makes all the variables integers unless you
  3.                 ' specify them as another type
  4.  
  5. '----------------------------------------------------------------------
  6. '        ISAMTOOT.L1   -  Source Code for Lesson #1 of ISAMTOOT
  7. '----------------------------------------------------------------------
  8.  
  9.  
  10. TYPE lesson1data                ' defining the fields of our first database.
  11.     name AS STRING * 35
  12.     address AS STRING * 35
  13.     cityStateZip AS STRING * 35
  14. END TYPE
  15.  
  16. DIM lesson1record AS lesson1data ' creating the memory block for a database
  17.                                  ' record, dimensioning the database.
  18.  
  19. '  now we open the database.  You will see later that several files -- MS
  20. '  calls them Tables -- can be in the same physical disk file.  Many other
  21. '  data management systems create two disk files for each "file," an index
  22. '  AND a datafile -- that can lead to real file polution in a multi-file
  23. '  relational application.  ISAM can put 13 into ONE physical disk enity
  24. '  and let it grow up to 128 MEGabytes.
  25.  
  26. OPEN "lesson1.MDB" FOR ISAM lesson1data "lesson1table" AS #1
  27.  
  28. '  This would be the logical place to create an index or indexES for
  29. '  this file.  ISAM creates one index itself -- it keeps track of the
  30. '  order in which the records were added to the file.  In the interest
  31. '  of simplicity, we will use this "internal" ISAM index.  If you don't
  32. '  specify an index, ISAM uses this one.
  33.  
  34. '  Now we are ready to add data to this database.  LINE INPUT is a "bad"
  35. '  programming practice in that you surrender control to the operator and
  36. '  don't have any control over the amount of data they type in, but it is
  37. '  entirely adequate for the purpose we intend.
  38. '
  39. '  YOU know that there are only 35 spaces available for each of the
  40. '  three fields and ISAM will lop off any excess.
  41. '
  42. '  We set up a simple DO/LOOP structure to gather the information we
  43. '  want and while it's a good programming process to swap database fields
  44. '  in and out of "work" fields -- sort of a electronic scratch pad --
  45. '  we will directly enter the fields in this lesson.
  46. '
  47. '  ISAM -- by virtue of the dimensioning statement -- knows these fields
  48. '  as lesson1record.[name of the field].  In a "real" application, you
  49. '  will likely opt for more cryptic name(s) to reduce the amount of typing
  50. '  you would have to do.  The TYPE needing a period in the name is reason
  51. '  enough to take MS's lead in using UpperAndLower case to name your
  52. '  variables rather than periods, dashes, underscores, etc.
  53.  
  54. DO
  55.  
  56.     CLS         ' just clear the screen for fresh workspace
  57.  
  58.                 ' the LOF() function, in ISAM, reports the
  59.                 ' number of records in the file, rather than
  60.                 ' the total number of bytes.
  61.  
  62.     PRINT , , "There are "; LOF(1); " records in the file."
  63.     PRINT
  64.     PRINT , : LINE INPUT "First & Last Name: "; lesson1record.name
  65.     PRINT , : LINE INPUT "          Address: "; lesson1record.address
  66.     PRINT , : LINE INPUT "City, State & Zip: "; lesson1record.cityStateZip
  67.     PRINT
  68.                 '  The operator has entered the data, now we
  69.                 '  let them decide what to do with it
  70.                 '
  71.                 '  TONS of code are written to get and control
  72.                 '  input . . . this is a VERY minimal approach.
  73.  
  74.     PRINT , "<S>ave    -    <E>dit      -       <Q>uit"
  75.     PRINT , "     Touch  S   or    E    or     Q"
  76.  
  77.     '  this next line makes sure we get an upper case entry . . .
  78.     '  dataDecision$ lends itself to being shortened to:  dd$
  79.  
  80.     dataDecision$ = UCASE$(INPUT$(1))
  81.  
  82.     ' A SELECT CASE  /  END SELECT block is a far better way to deal
  83.     ' with action options the operator has.  We will use it in later
  84.     ' lessons, but, for now, IF's will do what we need done.
  85.  
  86.     IF dataDecision$ = "S" THEN
  87.         INSERT #1, lesson1record        ' we save the record.
  88.         LOCATE 25, 40: PRINT " Saved "; ' and let the operator know.
  89.         SLEEP 1                         ' a moment to read the saved message
  90.         EXIT DO
  91.         END IF
  92.  
  93. LOOP UNTIL dataDecision$ = "Q"
  94.  
  95. CLS
  96. PRINT
  97. PRINT , "Total records now in the file: "; LOF(1)
  98. PRINT
  99. PRINT , "Now, we report the contents of the file . . . "
  100. PRINT
  101.  
  102. '  To report the contents of an ISAM file, there are three steps:
  103. '           1.  Set the index ISAM should use.
  104. '           2.  Move to the first record that matches selection criterion.
  105. '           3.  Retrieve that record.
  106. '
  107. '  For this first lesson, we won't specify any index, so ISAM will use
  108. '  the one it created when it stored the data.  We also are not picky about
  109. '  the particular record we want -- we want to see EVERYTHING we put in --
  110. '  so we'll just move to the first record and march through the file.
  111. '
  112. '  The DO UNTIL EOF is a useful device to make sure we step through the
  113. '  whole file.
  114. '
  115. MOVEFIRST #1
  116.  
  117. DO UNTIL EOF(1)
  118.     RETRIEVE #1, lesson1record          ' the data moves into memory.
  119.     PRINT , lesson1record.name          ' and we specify what parts
  120.     PRINT , lesson1record.address       ' of that record we want to
  121.     PRINT , lesson1record.cityStateZip  ' display on the screen
  122.     PRINT , "------------------------------------------"
  123.     SLEEP 1                             '  slows things down.
  124.     MOVENEXT #1                         '  step forward one record
  125. LOOP
  126.  
  127. PRINT
  128. PRINT , "We've reached the end of the file."
  129. PRINT
  130. PRINT , "Press Shift+F5 to restart, enter a"
  131. PRINT , "record and report file contents."
  132. PRINT
  133. PRINT
  134.  
  135.  
  136. END                  '  lesson 1 source code ends
  137.  
  138.  
  139.  
  140.